<?php
/*
 * This class is used for as Model for Project table 
 */
class Model_Project extends Model_Base {
    protected $_name = "tbl_project";
    protected $_primaryKey = "proj_id";
     
    public function getStatusArray() {
        return array(
            "" => "-- Select Status --",
            "1" => "Active",
            "0" => "Inactive"
        );
    }
    
    public function fetchEntryById($id) {
        $select = $this->select()
                ->from(array("proj" => "tbl_project"))
                ->where("proj_id = ?", $id)
                ->where("proj_status!= 2");
        $data = $this->fetchRow($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }
    

    /**
     *  This function is used to get project
     * @return null|Zend_Db_Table_Row_Abstract
     */
    public function fetchProject($where = "", $limit = "", $offset = "0", $order = "proj_id", $sort = "ASC") {
        $select = $this->select()
                ->from(array("proj" => "tbl_project"))
                ->where("proj_status != 2");
        if ($where != "") {
            $select->where($where);
        }
        if ($limit != "") {
            $select->limit($limit, $offset);
        }

        $select->order($order . " " . $sort);
        #echo $select; exit;
        $data = parent::fetchAll($select);
        if (!empty($data)) {
            return $data->toArray();
        } else {
            return array();
        }
    }
    

    /**
     *  This function is used to get total orders
     * @return int
     */
    public function getProjectCount($where) {
        $select = $this->select()
                ->from(array("proj" => "tbl_project"), Array("cnt" => "count(*)"))
                ->where("proj_status != 2");
        if ($where != "") {
            $select->where($where);
        }
        $rows = parent::fetchRow($select);
        return($rows->cnt);
    }
    /**
     *  This function is used to delete record
     * 
     */
    public function deleteProject($projArray) {
        if (is_array($projArray)) {
            foreach ($projArray as $_project) {
                $projectData = Array();
                $projectData = $this->fetchEntryById($_project);
                if (count($projectData) > 0) {
                    $data = array("proj_status" => "2");
                    $this->update($data, "proj_id =" . (int) $_project);
                }
            }
        } else {
            $proj_id = $projArray;
            $projectData = $this->fetchEntryById($proj_id);
            if (count($projectData) > 0) {
                $data = array("proj_status" => "2");
                $this->update($data, "proj_id =" . $proj_id);
            }
        }
    }


}?>